package chat.client;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.util.*;

import chat.*;
import chat.user.Group;
import chat.user.Message;
import chat.user.Request;

public class ClientReceiver implements Runnable{
	
	private Socket socket;
	private ObjectInputStream ois;
	
	public ClientReceiver(Socket s) {
		
		socket = s;
		
	}
	
	@Override
	public void run(){
		
		try{
			
			while(true){
				
				ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
				
				Request r = (Request) ois.readObject();
				
				ClientMain.addInMessage(r);
			}
		}
		catch(Exception e){e.printStackTrace();
			
		}
		
	}
	
	public void disconnect(){
		try{
			ois.close();
		}
		catch (Exception e){
			e.printStackTrace();
		}
	}
}
